package com.ctgu.server.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ctgu.server.dao.dto.AttendanceLocationDto;
import com.ctgu.server.dao.entity.AttendanceLocation;
import com.ctgu.server.dao.vo.Result;
import com.ctgu.server.service.AttendanceLocationService;
import com.ctgu.server.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 考勤地点表 前端控制器
 * </p>
 *
 * @author ctgu
 * @since 2023-06-13
 */
@RestController
@RequestMapping("/server/attendanceLocation")
@CrossOrigin
@Api(tags = "打卡信息操作接口")
public class AttendanceLocationController {

    @Autowired
    private AttendanceLocationService attendanceLocationService;
    @ApiOperation(notes = "新增打卡地点",value = "新增打卡地点")
    @PostMapping("/insert")
    public Result addAttendanceLocation(@Validated @RequestBody AttendanceLocationDto attendanceLocationDto){
        if(attendanceLocationDto.getAttendanceLocationList()==null){
            return ResultUtil.success("列表为空");
        }
        return attendanceLocationService.addAttendanceLocation(attendanceLocationDto);
    }
    @ApiOperation(notes = "删除打卡地点",value = "删除打卡地点")
    @GetMapping("/delete")
    public Result deleteAttendanceLocation(@RequestParam String userId,@RequestParam String attGrId ,@RequestParam String locationId){
//        if(attendanceLocationDto.getAttendanceLocationList()==null){
//            return ResultUtil.success("列表为空");
//        }
//        return attendanceLocationService.addAttendanceLocation(attendanceLocationDto);
        if(userId==null||attGrId==null||locationId==null){
            return ResultUtil.error("参数不能为空");
        }
        return attendanceLocationService.deleteAttendanceLocation(userId,attGrId,locationId);
    }

    @ApiOperation(notes = "删除打卡地点",value = "删除所有打卡地点")
    @GetMapping("/deleteAll")
    public Result deleteAll(@RequestParam String userId,@RequestParam String attGrId ){
//        if(attendanceLocationDto.getAttendanceLocationList()==null){
//            return ResultUtil.success("列表为空");
//        }
//        return attendanceLocationService.addAttendanceLocation(attendanceLocationDto);
        if(userId==null||attGrId==null){
            return ResultUtil.error("参数不能为空");
        }
        return attendanceLocationService.deleteAll(userId,attGrId);
    }

    @ApiOperation(notes = "查询当前组织所有打卡地点",value = "查询当前组织所有打卡地点")
    @GetMapping("/listGroupAll")
    public Result listGroupAll(@RequestParam String userId,@RequestParam String attGrId ){
        return ResultUtil.success(attendanceLocationService.listGroupAll(userId,attGrId));
    }

}

